package com.ext.springcloud.service.impl;

import cn.hutool.core.lang.Snowflake;
import com.ext.springcloud.dao.AccountDao;
import com.ext.springcloud.entity.Account;
import com.ext.springcloud.service.AccountService;
import com.ext.springcloud.utils.IdGeneratorSnowflake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

@Service
public class AccountServiceImpl implements AccountService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceImpl.class);

    @Resource
    private AccountDao accountDao;


    /**
     * 保存账户信息
     * @param account 账户信息
     */
    @Override
    public void setAccountInfo(Account account) {
//        account.setUserId(IdGeneratorSnowflake.snowflakeId()-1L);
        accountDao.insertAccount(account);
    }

    /**
     * 扣减账户金额
     * @param userId 用户Id
     * @param money 金额
     */
    @Override
    public void decrease(Long userId, BigDecimal money) {
        LOGGER.info("----> account-service中扣减用户余额开始");
        accountDao.decrease(userId, money);
        LOGGER.info("----> account-service中扣减用户余额开始");
    }
}
